const plugins = require.context(
  "./plugins" /* 文件目录 */ ,
  true /* 是否检索子目录 */ ,
  /.vue$/ /* 匹配文件的正则表达式 */
)

let allComponents = {}
plugins.keys().forEach(c => {
  const name = c.match(/\w+/)[0]
  const component = plugins(c)
  component.install = function (Vue, options) {
    Vue.component(name, component.default)
  }
  allComponents[name] = component
})

// module.exports = allComponents
const install = function (Vue, ops = {}) {
  for (let [name, component] of Object.entries(allComponents)) {
    Vue.component(name, component.default)
  }
}

export default {
  install,
  ...allComponents
}
